package cn.edu.hqu.cst.lecture03_03.service;

import java.util.List;

import org.springframework.stereotype.Service;

import cn.edu.hqu.cst.lecture03_03.mapper.ProductMapper;
import cn.edu.hqu.cst.lecture03_03.model.Product;

@Service
public class ProductService {
    private final ProductMapper productMapper;
    public ProductService(ProductMapper productMapper) {
        this.productMapper = productMapper;
    }
    public void addProduct(Product product) {
        productMapper.insert(product);
    }
    public void updateProduct(Product product) {
        productMapper.updateById(product);
    }
    public void deleteProduct(Long productId) {
        productMapper.deleteById(productId);
    }
    public Product getProductById(Long productId) {
        return productMapper.selectById(productId);
    }
    public List<Product> getAllProducts() {
        return productMapper.selectList(null);
    }
}
